<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        header {
            padding: 50px;

        }

        div {
            width: 200px;
            height: 200px;
            background-color: aqua;
        }

        main {
            background-image: linear-gradient(pink, aqua, green);

        }
    </style>
</head>

<body>
    <div></div>
    <main></main>
    <script>
        var div = document.querySelector('div');
        div.onclick = function (e) {
            // event 事件对象  记录当前事件信息
            // e.preventDefault() 阻止默认事件
            // e.stopPropagation() 阻止事件的传播
            // e.cancelBubble = true; 阻止事件的传播
            // e.target
            //console.log(e.target); 获取触发事件的标签
            // 事件对象.属性  获取鼠标位置
            //console.log(e.clientX);
            //console.log(e.clientY);
            //console.log(e.layerX);
            //console.log(e.layerY);


            // 获取最近的设置有定位属性的父级标签的偏移量 到html为止
            console.log(e.layerX);
            console.log(e.layerY);

        }
    </script>
</body>

</html>